package com.sj.排序算法;

import sun.security.util.Length;

import java.lang.reflect.Array;
import java.util.Arrays;

/**
 * @author sj
 * @date 2021/5/2
 **/
public class 选择排序 {
    public static void main(String[] args) {
        int[] arr = {2,2,65,4,5,8,2,12};
        for (int i = 0 ; i < arr.length - 1 ; i++ ){
            int temp = arr[i];
            int index = i;
            for (int j = i + 1; j < arr.length ; j ++){
                if (temp > arr[j]){
                    temp = arr[j];
                    index = j;
                }
            }
            if (index != i){
                arr[index] = arr[i];
                arr[i] = temp;
            }
        }
        for (int i = 0 ; i < arr.length; i++){
            System.out.print(arr[i] + "  ");
        }
    }
}
